package engine.graphics;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import org.newdawn.slick.opengl.Texture;

import engine.system.MADSystem;

public final class TextureManager {


	private static HashMap<String, Texture> textures;

	private static String latestTextureName = "" ; 
	
	public static void init(){
		textures = new HashMap<String, Texture>() ; 	
		String path = "res/" ; 
		File f = new File(path); 
		ArrayList<File> tmpFiles = new ArrayList<File>(); 
		MADSystem.getAllFilesFromDirectory(f, tmpFiles, "PNG");
		for(File f1: tmpFiles){
			String texPath = f1.getPath() ;
			String fileName = MADSystem.getFileName(f1); 
			addNewTexture(fileName, MADTextureLoader.loadTexture(texPath)) ; 
			System.out.println("Loading Texture: "+MADSystem.getFileName(f1)+", Extension: "+MADSystem.getFileExtension(f1));
		}
	}

	public static void addNewTexture(String name, Texture tex){
		textures.put(name, tex); 
	}

	public static HashMap<String, Texture> getTextures(){
		return textures; 
	}
	
	public static Texture getTextureByName(String name){
		return textures.get(name); 
	}
		
	public static void bindTexture(String texName){
//		if(!texName.equals(latestTextureName)){
			getTextureByName(texName).bind(); 
//		}
//		latestTextureName = texName ; 
	}
	
	public static void bindTextureForClass(Class<?> clazz){
		getTextureByName(clazz.getSimpleName().toLowerCase()).bind();
	}
	
}
